<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isErrorPage="true"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>员工列表</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/scripts/jquery-1.9.1.min.js"></script>
</head>
<body>
<h1>成功</h1>
<table border="1" cellpadding="5" cellspacing="0">
    <tr>
        <th>ID</th>
        <th>lastName</th>
        <th>email</th>
        <th>gender</th>
        <th>birth</th>
        <th>departmentName</th>
        <th>EDIT</th>
        <th>DELETE</th>
    </tr>
    <c:forEach items="${employees}" var="employee">
        <tr>
            <td>${employee.id}</td>
            <td>${employee.lastName}</td>
            <td>${employee.email}</td>
            <td>${employee.gender == 0 ? "女":"男"}</td>
            <td>${employee.birth}</td>
            <td>${employee.department.departmentName}</td>
            <td>
                <a href="${pageContext.request.contextPath}/employee/${employee.id}">edit</a>
            </td>
            <td>
                <a href="${pageContext.request.contextPath}/employee/${employee.id}" class="delBtn">delete</a>
            </td>
        </tr>
    </c:forEach>
</table>
<a href="${pageContext.request.contextPath}/toAddPage">添加员工</a>
<form action="${pageContext.request.contextPath}/quickAdd" method="post">
    <!--将员工的所有信息都写上，自动封装对象-->
    <input type="text" name="employeeInfo" value="employeeAdmin-admin@qq.com-1-101"/>
    <input type="submit" value="快速添加"/>
</form>
<form id="deleteForm" action="${pageContext.request.contextPath}/employee/${employee.id}" method="post">
    <input type="hidden" name="_method" value="delete"/>
</form>
<script type="text/javascript">
    $(function () {
        $(".delBtn").click(function () {
            //1.改变表单的action指向
            $("#deleteForm").attr("action",this.href);
            //2.提交表单
            $("#deleteForm").submit();
            return false;
        });
    });
</script>
</body>
</html>
